package com.yzh.dxpro.p7.taskSeven;
import java.io.IOException;
import java.util.Iterator;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import com.yzh.dxpro.p1.clear.TProperties;

public class SevenReduce extends Reducer<Text,IntWritable,NullWritable,Text>{

	@Override
	protected void reduce(Text key, Iterable<IntWritable> values,
			Reducer<Text, IntWritable, NullWritable, Text>.Context context) throws IOException, InterruptedException {
		//key:000042000000000000|513042498594|23    
				//System.out.println("~~~~~~~~~~~~reducer");
		//iterator迭代器，把数据一个个取出
		Iterator<IntWritable> it =values.iterator();		
		int sum=0;
		while(it.hasNext()) {
			IntWritable temp = it.next();
			int i =temp.get();
			sum = sum+i;
		
		}
		String keys[] = key.toString().split(TProperties.getValue("fileoutsplit"));
		StringBuffer sb = new StringBuffer();
		sb.append(keys[0]).append(TProperties.getValue("outfilesplit"))
		.append(keys[1]).append(TProperties.getValue("outfilesplit"))
		.append(sum).append(TProperties.getValue("outfilesplit"))
		.append(keys[2]).append(TProperties.getValue("outfilesplit"));
		Text ovalue = new Text(sb.toString());
		context.write(NullWritable.get(),ovalue);

	}
	
}
